// 请求封装
import axios from 'axios';

export default async (arr, successCallback = res => console.log(res.msg), errorCallback = res => console.log(res.msg)) => {
  let method = arr[0],
    url = arr[1],
    type = method === "GET" ? "params" : "data",
    data = arr[2] || {},
    headers = arr[3] || {},
    err = error => {
      const { status } = error.response;
      if (status === 500) return console.log('服务器错误')
      if (status === 404) return console.log('接口不存在')
    },
    res = await axios({ headers, method, url, [type]: data }).catch(err),
    code = res.data.code;
  if (code === 1) return successCallback(res.data)

  errorCallback(res.data)

}

